﻿namespace WMS6.Web.Administration
{
    using System;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoServiceRef;

    public class UserPermissionsDetail : BasePage
    {
        protected Button btnCancel;
        protected Button btnFinish;
        protected Button btnSaveContinue;
        protected HtmlForm F1033;
        protected HtmlInputHidden hdnActionID;
        protected Label Label1;
        protected Label lblMsg;
        protected Label lblRole;
        protected Label lblRoleId;
        protected Label lblRoleName;
        protected HtmlLink mycss;
        protected TextBox txtRoleId;
        protected TextBox txtRoleName;

        private bool AddRoleToUserRole()
        {
            if (!string.IsNullOrEmpty(this.txtRoleId.Text.Trim()))
            {
                try
                {
                    UserPermissionsInfo userPermission = base.PageQueryEntitySession as UserPermissionsInfo;
                    foreach (UserRoleInfo info in userPermission.UserRoleInfo)
                    {
                        if (info.RoleID == this.txtRoleId.Text.Trim())
                        {
                            this.lblMsg.Enabled = true;
                            this.lblMsg.Text = base.GetGlobalMsgResource("F1300_013");
                            return false;
                        }
                    }
                    UserRoleInfo userRoleInfo = new UserRoleInfo {
                        RoleID = this.txtRoleId.Text.Trim(),
                        UserID = userPermission.UserID
                    };
                    userPermission.UserRoleInfo.Add(userRoleInfo);
                    base.PageQueryEntitySession = userPermission;
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F1300_007") + ex.Message;
                    return false;
                }
                return true;
            }
            this.lblMsg.Text = base.GetGlobalMsgResource("F1300_014");
            return false;
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            base.Response.Redirect("UserPermissions.aspx?from=detail", false);
        }

        protected void btnFinish_Click(object sender, EventArgs e)
        {
            if (this.AddRoleToUserRole())
            {
                base.Response.Redirect("UserPermissions.aspx?from=detail", false);
            }
        }

        protected void btnSaveContinue_Click(object sender, EventArgs e)
        {
            if (this.AddRoleToUserRole())
            {
                this.lblMsg.Text = this.txtRoleId.Text + base.GetGlobalMsgResource("F1300_015");
                this.txtRoleId.Text = "";
                this.txtRoleName.Text = "";
            }
        }

        private void LoadData()
        {
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
            }
        }
    }
}

